home *** CD-ROM | disk | FTP | other *** search
- // Finder.cpp
-
- #pragma mark Includes
- #include <Pilot.h>
- #include <SysEvtMgr.h>
- #include <SysAll.h>
- #include "Finder_res.h"
- #include "pane.h"
- #include "main_form.h"
- #include "drawing.h"
- #include "prefs.h"
- #include "events.h"
- #include "commander.h"
- #include "da_mgr.h"
-
-
- // Internal Structures
- struct FinderAppInfoType {
- Byte replaceme;
- } ;
-
- // Internal Constants
- const unsigned long appFileCreator = 'MACS';
- const unsigned short appVersionNum = 0x01;
- const unsigned short appPrefID = 0x00;
- const unsigned short appPrefVersionNum = 0x01;
- const unsigned long version30 = 0x03000000;
- const unsigned long version20 = 0x02000000;
-
-
- // globals
- static main_form* g_main_form=NULL;
-
-
- #pragma mark Prototypes
- // Prototypes
- Err RomVersionCompatible(DWord requiredVersion, Word launchFlags);
- Err AppStart(void);
- void AppEventLoop(void);
- void AppStop(void);
- Boolean AppHandleEvent(EventPtr eventP);
- //-
- Boolean form_handle_event(EventPtr eventP);
-
-
- #pragma mark -
-
- /***********************************************************************
- *
- * FUNCTION: PilotMain
- *
- * DESCRIPTION: This is the main entry point for the application.
- *
- * PARAMETERS: cmd - word value specifying the launch code.
- * cmdPB - pointer to a structure that is associated with the launch code.
- * launchFlags - word value providing extra information about the launch.
- * RETURNED: Result of launch
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- DWord PilotMain( Word cmd, Ptr cmdPBP, Word launchFlags)
- {
- // variables
- Err error;
-
- // check for ROM version 3.0 or greater
- error = RomVersionCompatible (version30, launchFlags);
- if (error) return (error);
-
- switch (cmd) {
- case sysAppLaunchCmdNormalLaunch:
- error = AppStart();
- if (error)
- return error;
- AppEventLoop();
- AppStop();
- break;
-
- default:
- break;
- }
- return 0;
- }
-
- /***********************************************************************
- *
- * FUNCTION: RomVersionCompatible
- *
- * DESCRIPTION: This routine checks that a ROM version is meet your
- * minimum requirement.
- *
- * PARAMETERS: requiredVersion - minimum rom version required
- * (see sysFtrNumROMVersion in SystemMgr.h
- * for format)
- * launchFlags - flags that indicate if the application
- * UI is initialized.
- *
- * RETURNED: error code or zero if rom is compatible
- *
- * REVISION HISTORY:
- *
- ***********************************************************************/
- Err RomVersionCompatible(DWord requiredVersion, Word launchFlags)
- {
- DWord romVersion;
-
- // See if we're on in minimum required version of the ROM or later.
- FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
- if (romVersion < requiredVersion)
- {
- if ((launchFlags & (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) ==
- (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
- {
- FrmAlert (RomIncompatibleAlert);
-
- // Pilot 1.0 will continuously relaunch this app unless we switch to
- // another safe one.
- if (romVersion < version20)
- {
- // Err err;
-
- AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL);
- }
- }
-
- return (sysErrRomIncompatible);
- }
-
- return (0);
- }
-
-
- //
- // AppStart()
- //
- // Read the saved state of the application. Return 0 if no error.
- Err AppStart(void)
- {
- // variables
- FinderPrefsType* prefs = prefs::get_prefs();
- Word prefsSize;
-
- // Read the saved preferences / saved-state information.
- prefsSize = sizeof(FinderPrefsType);
- if (PrefGetAppPreferences(appFileCreator, appPrefID, prefs, &prefsSize, true)==
- noPreferenceFound)
- {
- // defaults for when no prefs are found
- prefs->trash_position.x = 140;
- prefs->trash_position.y = 150;
- prefs->show_startup = true;
- }
-
- if (prefs->show_startup)
- startup_sequence();
- prefs->show_startup = false;
-
- // show the Finder
- FrmGotoForm(MainForm);
-
- // constrain values
- PointType* p = &prefs->trash_position;
- if (p->x<0)
- p->x = 0;
- if (p->x>160)
- p->x = 160;
- if (p->y<10)
- p->y = 10;
- if (p->y>160)
- p->y = 160;
-
- return 0;
- }
-
-
- //
- // AppStop()
- //
- // Save the current state of the application.
- void AppStop(void)
- {
- // variables
- FinderPrefsType* prefs = prefs::get_prefs();
-
- // Write the saved preferences / saved-state information. This data
- // will be backed up during a HotSync.
- PrefSetAppPreferences (appFileCreator, appPrefID, appPrefVersionNum,
- prefs, sizeof (FinderPrefsType), true);
- }
-
-
- //
- // AppEventLoop()
- //
- void AppEventLoop(void)
- {
- // variables
- Word error;
- EventType event;
- Int32 sleep_time = 1 * SysTicksPerSecond(); // one second
-
- // instructions
- do {
- EvtGetEvent(&event, sleep_time);
- if (! SysHandleEvent(&event))
- if (! MenuHandleEvent(0, &event, &error))
- if (! AppHandleEvent(&event))
- FrmDispatchEvent(&event);
-
- } while (event.eType != appStopEvent);
-
- // dispose of main form
- if (g_main_form != NULL) {
- delete g_main_form;
- g_main_form = NULL;
- }
- }
-
-
-
- /***********************************************************************
- *
- * FUNCTION: AppHandleEvent
- *
- * DESCRIPTION: This routine loads form resources and set the event
- * handler for the form loaded.
- *
- * PARAMETERS: event - a pointer to an EventType structure
- *
- * RETURNED: true if the event has handle and should not be passed
- * to a higher level handler.
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- Boolean
- AppHandleEvent( EventPtr eventP)
- {
- Word formId;
- FormPtr frmP;
-
-
- if (eventP->eType == frmLoadEvent)
- {
- // Load the form resource.
- formId = eventP->data.frmLoad.formID;
- frmP = FrmInitForm(formId);
- FrmSetActiveForm(frmP);
-
- // Set the event handler for the form. The handler of the currently
- // active form is called by FrmHandleEvent each time it receives an
- // event.
- switch (formId)
- {
- case MainForm:
- {
- commander::set_default_commander(NULL);
- g_main_form = new main_form(frmP);
- FrmSetEventHandler(frmP, form_handle_event);
- commander::set_top_commander(g_main_form);
- }
- break;
-
- default:
- // ErrFatalDisplay("Invalid Form Load Event");
- break;
-
- }
- return true;
- }
-
- return false;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: GetObjectPtr
- *
- * DESCRIPTION: This routine returns a pointer to an object in the current
- * form.
- *
- * PARAMETERS: formId - id of the form to display
- *
- * RETURNED: VoidPtr
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static VoidPtr GetObjectPtr(Word objectID)
- {
- FormPtr frmP;
-
- frmP = FrmGetActiveForm();
-
- return (FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, objectID)));
- }
-
-
-
- #pragma mark -
-
- //
- // form_handle_event()
- //
- Boolean
- form_handle_event(EventPtr eventP) {
- // variables
- Boolean handled = false;
-
- if (g_main_form!=NULL)
- handled = g_main_form->handle_event(eventP);
-
- return handled;
- }
-
-
-